package num21;

import javax.lang.model.util.ElementScanner6;
import java.util.List;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/8 18:36
 * @Desc : https://leetcode-cn.com/problems/merge-two-sorted-lists/submissions/
 */
public class Solution {
  public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
    ListNode head = new ListNode();
    ListNode pn = head;
    while (l1 != null && l2 != null) {
      if (l1.val <= l2.val) {
        pn.next = l1;
        l1 = l1.next;
      } else {
        pn.next = l2;
        l2 = l2.next;
      }
      pn = pn.next;
    }
    if (l1 != null) {
      pn.next = l1;
    }
    if (l2 != null) {
      pn.next = l2;
    }
    return head.next;
  }

  public static void main(String[] args) {

  }
}

class ListNode {
  int val;
  ListNode next;

  ListNode() {
  }

  ListNode(int val) {
    this.val = val;
  }

  ListNode(int val, ListNode next) {
    this.val = val;
    this.next = next;
  }
}